package gspringboot

import (
	"os"
)

func getStringReplacePlaceholders(key string, props PropertiesSource) string {
	valStr := props.GetString(key)
	return os.Expand(valStr, func(embeddedKey string) string {
		return getStringReplacePlaceholders(embeddedKey, props)
	})
}

func getValue[T int | int64 | float64 | bool | string](key string, source PropertiesSource, defaultValFun func() T) T {
	valAny := source.Get(key)
	if valAny != nil {
		if v, ok := valAny.(T); ok {
			return v
		}
	}
	return defaultValFun()
}
